package sv.mecca.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import sv.mecca.form.Clinica1Form;
import sv.mecca.form.UsuariosForm;
import sv.mecca.modelo.Clinica1Modelo;


public class Clinica1Action  extends DispatchAction  {
	Clinica1Modelo oper = new Clinica1Modelo();
	
	/**
	 * Metodo para insertar una neva clinica
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public void insertar(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		oper.saveClinica1((Clinica1Form) form);
		this.listado(mapping, form, request, response);
	}



	/**
	 * Metodo para actualizar un registro de usuario
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public void actualizar(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		oper.updateClinica1((Clinica1Form) form);
		this.listado(mapping, form, request, response);
	}
	public void eliminar(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		oper.deleteclinica1((Clinica1Form) form);
		this.listado(mapping, form, request, response);
	}

	/**
	 * Metodo para mostrar todos los usuarios registrados
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	public void listado(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		request.setAttribute("usuariosList", oper.listado());
		((UsuariosForm) form).destroy();
		request.getRequestDispatcher("/Definiciones/Usuarios.jsp").forward(
				request, response);
	}
}
